<template>
  <div>
    <div><van-icon name="arrow-left" @click="goBack" /></div>
    <h2>欢迎您的登录</h2>
    <p>用户名：<input type="text" v-model="phone" /></p>
    <p>密码：<input type="password" v-model="userpass" /></p>
    <p>
      <input type="button" value="登录" @click="loginCheck" />
      <input type="button" value="去注册" @click="reg" />
    </p>
  </div>
</template>
  
  <script>
import { Toast } from "vant";

export default {
  name: "Reg",
  data() {
    return {
      phone: "18991274261",
      userpass: "123666",
    };
  },
  methods: {
    goBack() {
      this.$router.back();
    },
    loginCheck() {
      this.$service({
        method: "post",
        url: "/api/user/login",
        data: `loginname=${this.phone}&password=${this.userpass}`,
      }).then((res) => {
        if (res.data.code == 200) {
          Toast("登录成功！");
          sessionStorage.setItem("username", this.phone);
        //   this.$router.push("/My");
            if(this.$route.query.path){
                this.$router.push(this.$route.query.path); 
            }else{
                this.$router.push("/My");
            }
        } else {
          Toast("登录失败，用户名或者密码错误！");
        }
      });
    },
    reg() {
      this.$router.push("/Reg");
    },
  },
};
</script>
  
  <style>
</style>